/**
 * 
 */
package org.xelnaga.defiler.web.macro.variable;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.xelnaga.defiler.business.APILocator;
import org.xelnaga.defiler.web.macro.template.MacroHelperFactory;

/**
 * @author qijb
 *
 */
public class VariableMacroHelperFactory implements MacroHelperFactory, ApplicationContextAware {
	private ApplicationContext applicationContext;
	
	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		this.applicationContext = applicationContext;
	}

	/* (non-Javadoc)
	 * @see org.xelnaga.defiler.web.macro.template.MacroHelperFactory#createMacroHelper(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.util.Map)
	 */
	@Override
	public Object createMacroHelper(HttpServletRequest request,
			HttpServletResponse response, Map<String, Object> model) {
		APILocator apiLocator = getApiLocator();
		// TODO Auto-generated method stub
		return new VariableMacroHelper(request, apiLocator, model);
	}

	private APILocator getApiLocator() {
		return applicationContext.getBean(APILocator.class);
	}

}
